package com.my.study.designPatterns.statePattern;

public class GumballMachine {

    private State noQuarterState;

    private State hasQuarterState;

    private State soldState;

    private State soldOutState;

    private State bigWinnerState;

    private int count;

    private State state;


    public GumballMachine(int count) {
        this.noQuarterState = new NoQuarterState(this);
        this.hasQuarterState = new HasQuarterState(this);
        this.soldOutState = new SoldOutState(this);
        this.soldState = new SoldState(this);
        this.bigWinnerState = new BigWinnerState(this);
        this.count = count;
        if(count > 0){
            state = noQuarterState;
        }
    }


    public void insertQuarter(){

        state.insertQuarter();
    }


    public void rejectQuarter(){
        state.rejectQuarter();
    }


    public void turnCrank(){
        state.turnCrank();
    }

    public void dispense(){
        state.dispense();
    }

    public void releaseBall(){
        System.out.println("A gumball coms rolling out the slot......");
        if(count != 0){
            count --;
        }

    }

    public State getNoQuarterState() {
        return noQuarterState;
    }

    public void setNoQuarterState(State noQuarterState) {
        this.noQuarterState = noQuarterState;
    }

    public State getHasQuarterState() {
        return hasQuarterState;
    }

    public void setHasQuarterState(State hasQuarterState) {
        this.hasQuarterState = hasQuarterState;
    }

    public State getSoldState() {
        return soldState;
    }

    public void setSoldState(State soldState) {
        this.soldState = soldState;
    }

    public State getSoldOutState() {
        return soldOutState;
    }

    public void setSoldOutState(State soldOutState) {
        this.soldOutState = soldOutState;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public State getBigWinnerState() {
        return bigWinnerState;
    }

    public void setBigWinnerState(State bigWinnerState) {
        this.bigWinnerState = bigWinnerState;
    }
}
